package guiElements;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Collections;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class FabricResultsPanelMain extends JPanel {

	ArrayList<Fabric> fabricData;
	ResultsSortByPanel resultsSortByPanel;
	ResultsCriteriaPanel resultsCriteriaPanel;
	JScrollPane fabricResultsPane;
	FabricResultsPanel fabricResultsPanel;
		
	public FabricResultsPanelMain(ArrayList<Fabric> fabricData){
		this.fabricData = fabricData;
		
		setLayout(null);
		setSize(new Dimension(550,600));
		
		resultsSortByPanel = new ResultsSortByPanel(fabricData);
		resultsSortByPanel.setSize(new Dimension(460,50));
		resultsSortByPanel.setLocation(new Point(0,0));
		add(resultsSortByPanel);
		
		resultsCriteriaPanel = new ResultsCriteriaPanel();
		resultsCriteriaPanel.setSize(new Dimension(90,600));
		resultsCriteriaPanel.setLocation(new Point(460,0));
		add(resultsCriteriaPanel);
		
		fabricResultsPanel = new FabricResultsPanel(fabricData);
		fabricResultsPane = new JScrollPane(fabricResultsPanel);
		fabricResultsPane.setSize(new Dimension(460,550));
		fabricResultsPane.setLocation(new Point(0, 50));
		fabricResultsPane.getVerticalScrollBar().setUnitIncrement(40);
		fabricResultsPane.setBackground(Color.white);
		add(fabricResultsPane);
		
	}
	
	public void updateAfterSearch(ArrayList<Fabric> fabricData) throws MalformedURLException{
		Collections.sort(fabricData, new FabricComparator("fabricName"));
		fabricResultsPanel.updateResultsPanel(fabricData);
	}
	
	public void updateAfterSort(ArrayList<Fabric> fabricData, String sortBy) throws MalformedURLException{
		Collections.sort(fabricData, new FabricComparator(sortBy));
		fabricResultsPanel.updateResultsPanel(fabricData);
	}

	public ArrayList<Fabric> getFabricData() {
		return fabricData;
	}

	public void setFabricData(ArrayList<Fabric> fabricData) {
		this.fabricData = fabricData;
	}

	public ResultsSortByPanel getResultsSortByPanel() {
		return resultsSortByPanel;
	}

	public void setResultsSortByPanel(ResultsSortByPanel sortByPanel) {
		this.resultsSortByPanel = sortByPanel;
	}

	public ResultsCriteriaPanel getResultsCriteriaPanel() {
		return resultsCriteriaPanel;
	}

	public void setResultsCriteriaPanel(ResultsCriteriaPanel resultsCriteriaPanel) {
		this.resultsCriteriaPanel = resultsCriteriaPanel;
	}

	public FabricResultsPanel getFabricResultsPanel() {
		return fabricResultsPanel;
	}

	public void setFabricResultsPanel(FabricResultsPanel fabricResultsPanel) {
		this.fabricResultsPanel = fabricResultsPanel;
	}

	public JScrollPane getFabricResultsPane() {
		return fabricResultsPane;
	}

	public void setFabricResultsPane(JScrollPane fabricResultsPane) {
		this.fabricResultsPane = fabricResultsPane;
	}

}
